package com.yly.doctorapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yly.doctorapp.R;
import com.yly.doctorapp.bean.PrescriptionBean;
import com.zhcx.zhcxlibrary.utils.DateUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PrescriptionAdapter extends BaseAdapter {
    private Context mContext;
    private List<PrescriptionBean> mPrescriptionList;

    public PrescriptionAdapter(Context mContext, List<PrescriptionBean> mPrescriptionList) {
        this.mContext = mContext;
        this.mPrescriptionList = mPrescriptionList;
    }

    @Override
    public int getCount() {
        return mPrescriptionList.size();
    }

    @Override
    public Object getItem(int position) {
        return mPrescriptionList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = View.inflate(mContext, R.layout.layout_prescriptionitem, null);
        } else {
            view = convertView;
        }
        if (null != mPrescriptionList && mPrescriptionList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            holder.tvName.setText(mPrescriptionList.get(position).getName());
            holder.tvFrom.setText(mPrescriptionList.get(position).getTypeStr());
            holder.tvTime.setText(DateUtils.dateyyyyMMdd(new Date(mPrescriptionList.get(position).getCreatedTime())));
            holder.tvType.setText(mPrescriptionList.get(position).getStatusStr());
            getType(mPrescriptionList.get(position).getStatus(), holder);
        }
        return view;
    }

    private void getType(String type, ViewHolder holder) {
        switch (type){
            case "0":
                holder.tvType.setTextColor(0xffa0524b);
                break;
            case "1":
                holder.tvType.setTextColor(0xff999999);
                break;
            case "2":
                holder.tvType.setTextColor(0xffa0524b);
                break;
        }
    }

    static class ViewHolder {
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_from)
        TextView tvFrom;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_type)
        TextView tvType;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
